package com.vshining.grame;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * 系统内置用户
 */
public enum SystemUserName {
    Anonymous/*匿名用户*/(new char[]{0x11, 0x59, 0x43, 0x69, 0x21, 0x1FF, 0x12, 0x78, 0x56, 0x122}), // make sure Anonymous can not be sign in by user
    System/*系统，代表系统自身*/(new char[]{0x45f, 0x88, 0x38, 0x54, 0x102, 0xabc, 0x99, 0x0b, 0xbc, 0x92, 0x11}); // make sure System can not be sign in by user
    private Password password;

    SystemUserName(@NotNull char[] password) {
        this.password = new Password(password);
    }

    public Password getPassword() {
        return password;
    }

    static class Password implements CharSequence {
        private final static Password P0 = new Password(new char[0]);
        private final char[] password;

        public Password(@NotNull char[] password) {
            this.password = password;
        }

        @Override
        public int length() {
            return password.length;
        }

        @Override
        public char charAt(@Min(0) int index) {
            return password[index];
        }

        @Override
        public CharSequence subSequence(@Min(0) int start, int end) {
            int len = end - start;
            if (len > 0 && end < length()) {
                char[] newPassword = new char[len];
                java.lang.System.arraycopy(password, start, newPassword, 0, len);
                return new Password(newPassword);
            }
            return P0;
        }

        @Override
        public String toString() {
            return new StringBuilder(password.length).append(password).toString();
        }

        public char[] toCharArray() {
            return password.clone();
        }
    }
}
